package com.sks.service.base;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.stereotype.Service;

import com.sks.bean.QueryResult;
import com.sks.dao.base.DAO;
@Service
public abstract class BaseService<T> implements IBaseService<T> {
	private DAO dao;

	public DAO getDao() {
		return dao;
	}

	public void setDao(DAO dao) {
		this.dao = dao;
	}

	/**
	 * 获取记录总数
	 * 
	 * @param entityClass
	 *            实体类
	 * @return
	 */
	public long getCount() {
		return dao.getCount();
	}

	/**
	 * 清除一级缓存的数据
	 */
	public void clear() {
		dao.clear();
	}

	/**
	 * 保存实体
	 * 
	 * @param entity
	 *            实体id
	 */
	public void save(T entity) {
		dao.save(entity);
	}

	/**
	 * 更新实体
	 * 
	 * @param entity
	 *            实体id
	 */
	public void update(T entity) {
		dao.update(entity);
	}

	/**
	 * 删除实体
	 * 
	 * @param entityClass
	 *            实体类
	 * @param entityids
	 *            实体id数组
	 */
	public void delete(Serializable... entityids) {
		dao.delete(entityids);
	}

	/**
	 * 获取实体
	 * 
	 * @param <T>
	 * @param entityClass
	 *            实体类
	 * @param entityId
	 *            实体id
	 * @return
	 */
	public T find(Serializable entityId) {
		return (T) dao.find(entityId);
	}
	
	public T find(Serializable entityId, boolean throwException) {
		return (T) dao.find(entityId, throwException);
	}

	/**
	 * 获取分页数据
	 * 
	 * @param <T>
	 * @param entityClass
	 *            实体类
	 * @param firstindex
	 *            开始索引
	 * @param maxresult
	 *            需要获取的记录数
	 * @return
	 */
	public QueryResult<T> getScrollData(int firstindex, int maxresult,
			String wherejpql, Object[] queryParams,
			LinkedHashMap<String, String> orderby) {
		return dao.getScrollData(firstindex, maxresult, wherejpql, queryParams,
				orderby);
	}

	public QueryResult<T> getScrollData(int firstindex, int maxresult,
			String wherejpql, Object[] queryParams) {
		return dao.getScrollData(firstindex, maxresult, wherejpql, queryParams);
	}
	public QueryResult<T> getScrollDataByhql(int firstindex, int maxresult,
			String hql, Object[] queryParams) {
		return dao.getScrollDataByhql(firstindex, maxresult, hql, queryParams);
	}

	public QueryResult<T> getScrollData(int firstindex, int maxresult,
			LinkedHashMap<String, String> orderby) {
		return dao.getScrollData(firstindex, maxresult, orderby);
	}

	public QueryResult<T> getScrollData(int firstindex, int maxresult) {
		return dao.getScrollData(firstindex, maxresult);
	}

	public QueryResult<T> getScrollData() {
		return dao.getScrollData();
	}
	
	public List getListByJpql(String jpql, Object[] params) {
		return dao.getListByJpql(jpql, params);
	}
	
	public Object getObjectByJpql(String jpql, Object[] params) {
		return  dao.getObjectByJpql(jpql, params);
	}
}